package com.open.launcher.presenter;

import android.os.Bundle;


import com.open.launcher.bean.Content;
import com.open.launcher.callback.ContentCallback;
import com.open.launcher.service.AHservice;
import com.open.launcher.utils.APPLog;

import java.util.List;


/**
 * Created by wendal on 2017/9/11.
 */

public class TestRecyclePresenter {
    private boolean isDisplayed;
    private Callback callback;
    private List<Content> listContent;
    public interface Callback {
        void onError(int code, String msg);

        void onMovieCompleted(TestRecyclePresenter presenter, int count);
    }

    public interface ViewHolder {
        void setName(String name);
    }
    public void setDisplayed(boolean displayed) {
        isDisplayed = displayed;
    }
    //加载数据
    public void loadItem(Bundle params, Callback callback) {
        this.callback = callback;
        AHservice service = new AHservice();
        String url = params.getString("url");
        service.loadTestRecycleItem(url,new ItemLoadCallback());
    }
    public void onBindMovieView(ViewHolder holder, int position) {
        if(!isDisplayed){
            return;
        }
        holder.setName(listContent.get(position).name);
    }
    class ItemLoadCallback implements ContentCallback {
        @Override
        public void onFailed(String arg0, String arg1) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onLoadComplete(String contentID, int pageNumber, int count,
                                   List<Content> contents) {
            // TODO Auto-generated method stub
            if (callback == null || !isDisplayed) {
                APPLog.printInfo("onLoadComplete:callback :");
                return;
            }
            listContent = contents;
            callback.onMovieCompleted(TestRecyclePresenter.this, count);
        }
        @Override
        public void onLoading(String arg0) {
            // TODO Auto-generated method stub
        }
    }
}
